import React, {Component} from 'react'
import MessageNotification from './component/notification/index'
import './style/App.css'
import { connect } from 'react-redux'
import TwsLayout from './component/tws-layout'
import {
    HashRouter as Router,
    Route
} from 'react-router-dom'
import {getLangFromLocalStorage} from './constant/lang-util'
import locales from './locales'
import {LocaleProvider} from 'antd'
import { IntlProvider } from 'react-intl'

class App extends Component {
  render () {
    const lang = this.props.lang || getLangFromLocalStorage()
    const langData = locales[lang]

    return (
      <IntlProvider locale={langData.intlLocale} messages={langData.intlMessage}>
        <LocaleProvider locale={langData.locale}>
          <Router>
            <TwsLayout lang={lang}>
              <Route exact path='/' component={MessageNotification} />
            </TwsLayout>
          </Router>
        </LocaleProvider>
      </IntlProvider>
    )
  }
}

const mapStateToProps = ({lang}) => ({lang})

export default connect(mapStateToProps)(App)
